<?php defined('SYSPATH') OR die('No direct access allowed.'); ?>
	<script type="text/javascript">
	 	dojo.require("dijit.Editor");
		dojo.require("dijit.form.ValidationTextBox");
		dojo.require("dijit.form.FilteringSelect");
		dojo.require("dijit.form.DateTextBox");
		dojo.require("dijit.form.RadioButton");
		dojo.require("dojox.validate.regexp");
		dojo.require("dojo.parser");
	</script>

		<script language="javascript">
						$(document).ready(function() {
							$("#btnCancel").click(function() {
								var uri = ISS.lang.getBasePath()+'index.php';
								window.location = uri;
							});
							
							$("#cboAlbum").change(function() {
								var uri = ISS.lang.getBasePath()+'index.php/playlist/create/ajax_page/'+this.value;
								ISS.Ajax.Caller.request(uri, null);
							});
							
							$('#Add').click(function(){
								var songId = $("#cboSong").val();
								var songText = $("#cboSong :selected").text();

								//------- set theValue of input hidden  if 0 set 1 ----
								  var numi = document.getElementById('theValue');
								  var num = (document.getElementById('theValue').value -1)+ 2;
								  numi.value = num;

								  var divID = 'songDIV'+num;
								  var hidID = 'hidID' + num;
								

								var content = '<div id="'+divID+'">- '+songText+' has been added! &nbsp;<a href="javascript:;" onclick="removeDIV(\''+divID+'\')">Delete</a><input type="hidden" value="'+ songId+'" id="'+ hidID+'" name="'+ hidID+'" /></div>';
								$('#myDiv').append(content)
							});
						
						
						});

						function removeDIV(divID){
								$('#'+divID).remove();
						}
				</script>





	<?php 	
	if (!empty($form['cover_picture'])) {
		echo html::Stylesheet(
			array
			(
				'media/css/playlist_picture_block.css',
			),
			array
			(
				'screen',
			)
		);	
	}
	else {
		echo html::Stylesheet(
			array
			(
				'media/css/playlist_block.css',
			),
			array
			(
				'screen',
			)
		);	
	}
	?>
<?php print form::open_multipart('playlist/create/createplaylist/');?>	
				<div id="albumContainer">

					
						<div id="albumBlock">
							<div id="albumBlockTop">
							  <h3><?php //echo ($mode=='add') ? 'เพิ่มอัลบัม' : 'แก้ไขอัลบัม'; 
							  echo 'playlist'; ?></h3>
							  <p><?php //echo (empty($status) ? 'กรุณาระบุข้อมูลให้ครบถ้วน' : html::specialchars($status)); 
							  echo 'กรอกข้อมูล'; ?></p>
							</div>
							<div id="albumBlockBody">
											<table width="100%">
												<tr>
													<td><div class="mandatory">Title::</div></td>
													<td>														
														<input type="text" name="txtTitle" value="<?php echo html::specialchars($form['txtTitle']) ?>"
															dojoType="dijit.form.ValidationTextBox"
															trim="true"
															required="true"
															invalidMessage="กรุณาระบุชื่อเข้าใช้งาน"
														/>
													</td>
												</tr>
												<tr>
													<td><div class="mandatory">Description::</div></td>
													<td>														
														<input type="text" name="txtDesc" value="<?php echo html::specialchars($form['txtDesc']) ?>"
															dojoType="dijit.form.ValidationTextBox"
															trim="true"
															required="false"
														/>
													</td>
												</tr>
												<tr>
													<td><div class="mandatory">Logo::</div></td>
													<td>														
														<?php
															if (!empty($form['txtPicture'])) {
																echo '<img id=imgPicture  alt="'. html::specialchars($form['txtTitle']) .'" src="'. url::base() . html::specialchars($form['txtPicture']) .'" />';
																echo '<br/>';
															} 
															$attributes = array('name' => 'txtPicture');
															echo form::upload($attributes, '');	
														?>
													</td>
												</tr>
												<tr>
													<td>&nbsp;</td>
													<td>&nbsp;</td>
												</tr>
												<tr>
													<td><div class="mandatory">Select Album::</div></td>
													<td>
															<select style="width:150px"
																id="cboAlbum"
																name="cboAlbum">
																<option value="0"></option>
																<?php foreach ($albums as $album): ?>
																<option value="<?php echo $album['id']; ?>"><?php echo html::specialchars($album['title']); ?></option>
																<?php endforeach ?>	
																
															</select>

													</td>
												</tr>							
												<tr>
													<td><div class="mandatory">Select Song::</div></td>
													<td>

															<div id="songs">
																<select style="width:150px"	id="cboSong"	name="cboSong">
																<option value="0"></option>
																	<?php foreach ($songs as $song): ?>
																	<option value="<?php echo $song['album_id'].'-'.$song['track_no']; ?>"><?php echo html::specialchars($song['title']); ?></option>
																	<?php endforeach ?>	
																</select>
															</div>
													</td>
												</tr>
												<tr>
													<td>&nbsp;</td>
													<td>
															<input type="button" id="Add" value="Add to playlist" />
															<input type="hidden" value="<?php if (isset($form['numhidDIV'])) { echo $form['numhidDIV']; }else { echo 0; }  ?>" id="theValue" />
																<?php 
																	if (isset($form['hidMode'])) { 
																		echo '<input type="hidden" id="hidMode" name="hidMode" value="'. $form['hidMode'] .'" />';
																	} 
																?>
													</td>
												</tr>
												<tr>
													<td colspan="2" style="padding-left:60px;padding-top:20px;">
														<div id="myDiv" >
															<?php
																if (isset($form['arrhidDIV'])){
																	foreach ($form['arrhidDIV'] as $hidDIV):
																		echo $hidDIV;
																	endforeach;
																}
															?>
														</div>		
													</td>
												</tr>
												<tr>
													<td colspan="2" style="text-align:center;"><br />
															<input type="submit" id="btnSave" name="btnSave" value="บันทึก" />&nbsp;
															<input type="button" id="btnCancel" name="btnCancel" value="ยกเลิก" />
													</td>
												</tr>
											</table>								


							</div>
							<div id="albumBlockBot">&nbsp;</div>
						 </div>
						 
				 </div>
	</form>